
package com.imelite.qyh.data.util;

import com.imelite.qyh.data.NPS_Bean;
import com.imelite.qyh.factory.OrgDepFactory;
import com.imelite.qyh.model.EliteCRMView_dcwj;
import com.imelite.qyh.model.OrgDep;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

public class NPS_Util {

    public static List<NPS_Bean> Init(List<EliteCRMView_dcwj> dcwjList,String year,String quarter){
        List<NPS_Bean> npsBeanList=new ArrayList<>();
        List<OrgDep> orgDepList= OrgDepFactory.selectByCenter();//获得所有校区
        for(OrgDep o:orgDepList){
            NPS_Bean npsBean=new NPS_Bean();
            npsBean.setIddep(o.getId());
            npsBean.setIddepSname(o.getSname());
            npsBean.setYear(year);
            npsBean.setQuarter(quarter);
            getCenterDcwj(dcwjList,o.getId(),npsBean);
            npsBeanList.add(npsBean);
        }
        return npsBeanList;
    }
    //更具校区ID筛选出调查问卷集合中属于目标校区的数据
    private static void getCenterDcwj(List<EliteCRMView_dcwj> dcwjList,String depId,NPS_Bean npsBean){
        List<EliteCRMView_dcwj> dcwjs=new ArrayList<>();
        List<EliteCRMView_dcwj> eliteCRMView_dcwjList_a=new ArrayList<>();
        List<EliteCRMView_dcwj> eliteCRMView_dcwjList_b=new ArrayList<>();
        List<EliteCRMView_dcwj> eliteCRMView_dcwjList_c=new ArrayList<>();
        List<EliteCRMView_dcwj> eliteCRMView_dcwjList_d=new ArrayList<>();
        double a=0,b=0,c=0,d=0;
        for(EliteCRMView_dcwj e:dcwjList){
            if(e.getIddep().equals(depId)){
                switch (e.getWt1()){
                    case "A. 肯定会推荐精英英语"://Will definitely recommend
                        eliteCRMView_dcwjList_a.add(e);
                        a++;
                        break;
                    case "B. 可能会推荐精英英语"://Will probably recommend
                        eliteCRMView_dcwjList_b.add(e);
                        b++;
                        break;
                    case "C. 可能不会推荐精英英语"://Will probably not recommend
                        eliteCRMView_dcwjList_c.add(e);
                        c++;
                        break;
                    case "D. 告诉朋友们不要来精英英语"://Will tell friends and family NOT to visit Elite Learning
                        eliteCRMView_dcwjList_d.add(e);
                        d++;
                        break;
                }
                dcwjs.add(e);
            }
        }

        npsBean.setDcwjList(dcwjs);
        npsBean.setDcwjList_a(eliteCRMView_dcwjList_a);
        npsBean.setDcwjList_b(eliteCRMView_dcwjList_b);
        npsBean.setDcwjList_c(eliteCRMView_dcwjList_c);
        npsBean.setDcwjList_d(eliteCRMView_dcwjList_d);

        if(dcwjs.isEmpty() || dcwjs.size()==0){
            npsBean.setScore("0");
        }else{
            int total=dcwjs.size();
            double OverallScore= a/total+0.5*b/total-0.5*c/total-d/total;
            BigDecimal bg = new BigDecimal(OverallScore*100);
            double f1 = bg.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
            npsBean.setScore(f1+"");
        }
    }
}

